package com.apache.client;

import java.util.Map;

import com.apache.api.vo.ResultEntity;
import com.apache.attachment.mommon.ToolsUtil;
import com.apache.client.protocol.HttpProtocolService;
import com.apache.client.protocol.HttpsProtocolService;
import com.apache.client.protocol.SocketProtocolService;

public class AttaProtocolClient {

	private static AttaProtocolClient instance;
	private SocketProtocolService socketService;
	private HttpProtocolService httpService;
	private HttpsProtocolService httpsService;

	public AttaProtocolClient() {
		socketService = new SocketProtocolService();
		httpService = new HttpProtocolService();
		httpsService = new HttpsProtocolService();
	}

	public static AttaProtocolClient getInstance() {
		if (instance == null) {
			instance = new AttaProtocolClient();
		}
		return instance;
	}

	public ResultEntity doService(String beanId, String methodKey, Map<String, Object> params) {
		String atta_protype = ToolsUtil.getInstance().getValueByKey("atta_protype");
		if (ToolsUtil.isNull(atta_protype)) {
			atta_protype = "socket";
		}
		if ("socket".equals(atta_protype)) {
			return socketService.doService(beanId, methodKey, params);
		} else if ("http".equals(atta_protype)) {
			return httpService.doService(beanId, methodKey, params);
		} else {
			return httpsService.doService(beanId, methodKey, params);
		}
	}
}
